<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/1/12
 * Time: 10:29
 */
namespace app\models;

use yii;
use yii\db\Query;
use app\lib\Redis;

/**
 *部门表
 *
 */
class Department
{
    use Redis;

    private $table;

    private $redis;

    public function __construct()
    {
        $this->table = yii::$app->db->tablePrefix.'department';
        $this->redis = $this->getInstance();
    }

    public function all()
    {
        $redisKey = 'staff:department';
        if ($list = $this->redis->get($redisKey)) {
            return json_decode($list,true);
        } else {
            $db = new Query();
            $list = $db->select('*')->from($this->table)->all();
            $this->redis->setex($redisKey,3600,json_encode($list));
            return $list;
        }

    }
}